package com.coda.controller;

import com.coda.adminVo.room.RoomDetailVo;
import com.coda.adminVo.room.RoomItemVo;
import com.coda.adminVo.room.RoomQueryVo;
import com.coda.adminVo.room.RoomSubmitVo;
import com.coda.constant.StatusConstant;
import com.coda.entity.RoomInfo;
import com.coda.result.PageResult;
import com.coda.result.Result;
import com.coda.service.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/room")
@Api(tags = "条件分页查询房间列表")
public class RoomController {
    @Autowired
    private RoomService roomService;
    /**
     * 分页查询房间列表信息
     */
    @GetMapping("/pageItem")
    @ApiOperation("分页查询房间列表信息")
    public Result<PageResult> page(Integer current, Integer size, RoomQueryVo roomQueryVo){
        PageResult pageResult = roomService.getPageList(current,size,roomQueryVo);
        return Result.ok(pageResult);
    }
    /**
     * 根据id删除房间信息
     */
    @DeleteMapping("/removeById")
    @ApiOperation(value = "根据id删除房间信息")
    public Result deleteRoomById(Long id){
        roomService.deleteRoomById(id);
        return Result.ok();
    }
    /**
     * 保存或更新房间信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新房间信息")
    public Result saveOrUpdate(@RequestBody RoomSubmitVo roomSubmitVo){
        roomService.saveOrUpdate(roomSubmitVo);
        return Result.ok();
    }
    /**
     * 根据id获取房间详细信息
     */
    @GetMapping("/getDetailById")
    @ApiOperation("根据id获取房间详细信息")
    public Result<RoomDetailVo> getDetailById(Long id){
        RoomDetailVo roomDetailVo = roomService.getRoomDetailVO(id);
        return Result.ok(roomDetailVo);
    }
    /**
     * 根据公寓id查询房间信息列表
     */
    @GetMapping("/listBasicByApartmentId")
    @ApiOperation("根据公寓id查询房间信息列表")
    public Result<List<RoomInfo>> getRoomList(Long id){
        List<RoomInfo> roomInfoList = roomService.getRoomList(id);
        return Result.ok(roomInfoList);
    }
    /**
     * 根据id修改房间发布状态
     */
    @PostMapping("/updateReleaseStatusById")
    @ApiOperation("根据id修改房间发布状态")
    public Result updateRelease(Long id ,Integer status){
        roomService.updateRelease(id,status);
        return Result.ok();
    }
}
